home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
PictPort.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-12
|
6KB
|
354 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "PictPort.h"
#include "Class.h"
#include "String.h"
#include "Picture.h"
#include "ObjArray.h"
#include "MemBuf.h"
NewMetaImpl0(PictPort, PrintPort);
//---- PictPort ----------------------------------------------------------------
PictPort::PictPort(Picture *p) : PrintPort("PICT")
{
hascolor= TRUE;
pict= p;
DevOpenPage(0);
}
PictPort::~PictPort()
{
FlushMyText();
PutCode(cPicEnd);
if (pict)
pict->Set(pagebbox, (byte*) pagebuf->Base(), (int) pagebuf->tell(), map);
SafeDelete(pagebuf);
}
void PictPort::DevOpenPage(int)
{
pagebuf= new MemBuf;
map= new ObjArray;
lastfont= 0;
lastextent= lastpos= gPoint0;
lastdia= gPoint0;
lastpsz= 1;
laststartangle= lastendangle= 0;
lastcap= eDefaultCap;
for (int i= 0; i < map->Size(); i++)
map->AtPut(i, 0);
//pagebuf->seek(0);
}
void PictPort::DevClosePage()
{
FlushMyText();
PutCode(cPicEnd);
if (pict)
pict->Set(pagebbox, (byte*) pagebuf->Base(), (int) pagebuf->tell(), map);
}
void PictPort::PutInt(int i)
{
/*
PutByte(i >> 24);
PutByte(i >> 16);
PutByte(i >> 8);
PutByte(i);
*/
pagebuf->sputn((char*) &i, 4);
}
void PictPort::PutShort(short s)
{
/*
PutByte(i >> 8);
PutByte(i);
*/
pagebuf->sputn((char*) &s, 2);
}
void PictPort::PutPoint(byte code, Point p)
{
if (p.x != 0) {
if (p.x >= -128 && p.x < 128) {
code+= 1 << 2;
} else if (p.x >= -32768 && p.x < 32768) {
code+= 2 << 2;
} else {
code+= 3 << 2;
}
}
if (p.y != 0) {
if (p.y >= -128 && p.y < 128) {
code+= 1;
} else if (p.y >= -32768 && p.y < 32768) {
code+= 2;
} else {
code+= 3;
}
}
PutCode(code);
if (p.x != 0) {
if (p.x >= -128 && p.x < 128) {
PutByte(p.x);
} else if (p.x >= -32768 && p.x < 32768) {
PutShort(p.x);
} else {
PutInt(p.x);
}
}
if (p.y != 0) {
if (p.y >= -128 && p.y < 128) {
PutByte(p.y);
} else if (p.y >= -32768 && p.y < 32768) {
PutShort(p.y);
} else {
PutInt(p.y);
}
}
}
void PictPort::PutPos(Point pos)
{
Point delta= pos-lastpos;
lastpos= pos;
if (delta.x >= -32 && delta.x < 32 && delta.y == 0)
PutCode(cPicXMove0+delta.x+32);
else
PutPoint(cPicMove, delta);
}
void PictPort::PutRect(Rectangle *r)
{
PutPos(r->origin);
Point delta= r->extent - lastextent;
if (delta.x != 0 || delta.y != 0) {
lastextent= r->extent;
PutPoint(cPicExtent, delta);
}
}
void PictPort::PutInk()
{
if (lastink != lastink2) {
PutCode(cPicInk);
PutShort(map->Index(lastink2= lastink));
}
}
void PictPort::PutSize(int s)
{
if (s >= 0 && lastpsz != s) {
PutCode(cPicPensize);
PutByte(s);
lastpsz= s;
}
}
void PictPort::PutCap(GrLineCap cap)
{
if (cap != lastcap) {
PutCode(cPicPenCap);
PutByte(cap);
lastcap= cap;
}
}
void PictPort::PutAngle(int s, int e)
{
if (s != laststartangle) {
PutCode(cPicStartAngle);
PutShort(s);
laststartangle= s;
}
if (e != lastendangle) {
PutCode(cPicEndAngle);
PutShort(e);
lastendangle= e;
}
}
void PictPort::PutDia(Point e)
{
if (e != lastdia) {
PutPoint(cPicCornerDia, e);
lastdia= e;
}
}
void PictPort::DevClip(Rectangle clr)
{
PutRect(&clr);
PutCode(cPicClip);
}
void PictPort::DevStrokeLine(int psz, Rectangle *r, GrLineCap cap, Point p1, Point p2)
{
Merge(r);
PutInk();
p2-= p1;
PutSize(psz);
PutCap(cap);
PutPos(p1);
PutPoint(cPicLine, p2);
lastpos+= p2;
}
extern Ink *gTbInk;
void PictPort::DevShowChar(Font *fp, Point, byte c, Rectangle *r)
{
Merge(r);
lastink= gTbInk;
PutInk();
PutPos(r->origin+Point(0, fp->Ascender()));
if (lastfont != fp) {
PutCode(cPicFont);
PutShort(map->Index(lastfont= fp));
}
if (c >= 128 || c < 32) // need escape
PutCode(cPicEsc);
PutChar(c);
lastpos.x+= fp->Width(c);
}
void PictPort::DevStrokeRect(int psz, Rectangle *r)
{
Merge(r);
PutInk();
PutRect(r);
PutSize(psz);
PutCode(cPicStrokeRect);
}
void PictPort::DevFillRect(Rectangle *r)
{
Merge(r);
PutInk();
PutRect(r);
PutCode(cPicFillRect);
}
void PictPort::DevStrokeOval(int psz, Rectangle *r)
{
Merge(r);
PutInk();
PutRect(r);
PutSize(psz);
PutCode(cPicStrokeOval);
}
void PictPort::DevFillOval(Rectangle *r)
{
Merge(r);
PutInk();
PutRect(r);
PutCode(cPicFillOval);
}
void PictPort::DevStrokeRRect(int psz, Rectangle *r, Point dia)
{
Merge(r);
PutInk();
PutRect(r);
PutSize(psz);
PutDia(dia);
PutCode(cPicStrokeRRect);
}
void PictPort::DevFillRRect(Rectangle *r, Point dia)
{
Merge(r);
PutInk();
PutRect(r);
PutDia(dia);
PutCode(cPicFillRRect);
}
void PictPort::DevStrokeWedge(int psz, GrLineCap cap, Rectangle *r, int s, int d)
{
Merge(r);
PutInk();
PutRect(r);
PutSize(psz);
PutCap(cap);
PutAngle(s, d);
PutCode(cPicStrokeWedge);
}
void PictPort::DevFillWedge(Rectangle *r, int s, int d)
{
Merge(r);
PutInk();
PutRect(r);
PutAngle(s, d);
PutCode(cPicFillWedge);
}
void PictPort::DevStrokePolygon(Rectangle *r, Point *pts, int n, GrPolyType t,
int psz, GrLineCap cap)
{
Merge(r);
PutPos(r->origin);
PutInk();
PutSize(psz);
PutCap(cap);
PutCode(cPicStrokePoly);
PutByte(t);
PutShort(n);
for (int i= 0; i < n; i++)
PutPoint(0, pts[i]);
}
void PictPort::DevFillPolygon(Rectangle *r, Point *pts, int n, GrPolyType t)
{
Merge(r);
PutPos(r->origin);
PutInk();
PutCode(cPicFillPoly);
PutByte(t);
PutShort(n);
for (int i= 0; i < n; i++)
PutPoint(0, pts[i]);
}
void PictPort::DevShowBitmap(Rectangle *r, struct Bitmap *bmp)
{
Merge(r);
PutInk();
PutRect(r);
PutCode(cPicShowBitmap);
PutShort(map->Index(bmp));
}
void PictPort::DevShowPicture(Rectangle *r, Picture *pict)
{
Merge(r);
PutRect(r);
PutCode(cPicShowPicture);
PutShort(map->Index(pict));
}
void PictPort::DevGiveHint(int code, int len, void *vp)
{
PutCode(cPicHint);
PutInt(code);
if (vp) {
PutInt(len);
pagebuf->sputn((char*) vp, len);
} else
PutInt(0);
}